Get the src part of a string [duplicate]

Posted by Kay Lakeman on Stack Overflow See other posts from Stack Overflow or by Kay Lakeman
Published on 2013-06-30T16:09:11Z Indexed on 2013/06/30 16:21 UTC
Read the original article Hit count: 215

Filed under:
|
|

This question already has an answer here:

First post ever here, and i really hope you can help.

I use a database where a large piece of html is stored, now i just need the src part of the image tag.

I already found a thread, but i just doesn't do the trick.

My code:

Original string:

<p><img alt=\"\" src=\"http://domain.nl/cms/ckeditor/filemanager/userfiles/background.png\" style=\"width: 80px; height: 160px;\" /></p>

How i start:

$image = strip_tags($row['information'], '<img>');
echo stripslashes($image); 

This returns:

<img alt="" src="http://domain.nl/cms/ckeditor/filemanager/userfiles/background.png" style="width: 80px; height: 160px;" />

Next step: extract the src part:

preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $image, $matches);

echo $matches ;

This last echo returns:

Array

What is going wrong?

Thanks in advance for your anwser.

© Stack Overflow or respective owner

Related posts about php

Related posts about image